<template>
  <base-breadcrumb>
    <searchData :search-data="searchArr" @search="search" />
    <a-card :bordered="false">
      <list-table
        ref="table"
        :columns="columns"
        :statistics-config="{ use: true, statistics, temp }"
        :request="loadData"
        :exportConfig="{ use: true,select: '物资招标定标',all: '物资招标定标'}"
      >
        <template slot="prefix">
          <a-button v-btnPermission="'mm_036_add_01'" type="primary" icon="plus" @click="handleEdit(null,1)">
            新增
          </a-button>
        </template>
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }}</span>
        <template slot="auditStatusStr" slot-scope="text, record">
          <list-status :status="record.auditStatus" :text="text" />
        </template>
        <template slot="operation" slot-scope="text, record">
          <div class="pub-table-list-action">
            <span v-btn-permission="'mm_036_loo_02'" @click="handleEdit(record, 3)">查看</span>
            <!--            <span @click="handleEdit(record, 2)">编辑</span>-->

            <template v-if="record.auditStatus === 'DRAFT' || record.auditStatus === 'REJECTED'">
              <span v-btn-permission="'mm_036_edi_03'" @click="handleEdit(record, 2)">编辑</span>
              <span v-btn-permission="'mm_036_del_04'" @click="handleDel(record.id)">删除</span>
            </template>
            <approval-button :id="record.id" :status="record.auditStatus"
                             v-if="record.auditStatus === 'PAST' || record.auditStatus === 'SUBMITTED' || record.auditStatus === 'REJECTED' || record.auditStatus === 'REVOKEIN' || record.auditStatus === 'REVOKE' || record.auditStatus === 'ABOLISH' || record.auditStatus === '1' || record.auditStatus === '3' || record.auditStatus === 'COMMIT'|| record.auditStatus === '2' "
            />
          </div>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany'
import SelectProject from '@/components/Select/SelectProject'
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { deleteByMain, findListByMain, findListCount } from '@/api/material/procurement/tender'

export default {
  name: 'a' + Date.now(),
  data() {
    return {
      queryParam: {},
      statistics: {}, // 统计参数
      searchArr: [
        // 搜索框
        {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
        // {
        //   name: '所属分公司',
        //   valueKey: 'branchComId',
        //   type: SelectSubCompany
        // },
        // {
        //   name: '项目名称',
        //   type: SelectProject,
        //   valueKey: 'projectId',
        //   keyValue: 'branchComId'
        // },
        {
          name: '物资招标定标编号',
          value: 'selectionCode',
          type: 'input'
        },
        {
          name: '物资招标评审会签编码',
          value: 'tenderCountersignCode',
          type: 'input'
        },
        {
          name: '状态',
          value: 'auditStatus',
          type: 'select',
          data: this.STATUS
        },
        {
          name: '创建人',
          value: 'creatorName',
          type: 'input'
        },
        {
          name: '创建时间',
          value: 'createTime',
          type: 'dateRangeFormat'
        }
      ],
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          scopedSlots: { customRender: 'index' },
          width: 70
        }, {
          title: '所属分公司',
          dataIndex: 'branchComName',
          width: 150
        },
        {
          title: '物资招标定标编号',
          dataIndex: 'selectionCode',
          width: 180
        },
        {
          title: '项目名称',
          dataIndex: 'projectName',
          width: 150
        },
        {
          title: '物资招标评审会签编码',
          dataIndex: 'tenderCountersignCode',
          width: 180
        },
        {
          title: '投标人数量',
          dataIndex: 'tenderSize',
          width: 160
        },
        {
          title: '中标人数量',
          dataIndex: 'winningSize',
          width: 160
        },
        {
          title: '创建人',
          dataIndex: 'creatorName',
          width: 160
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          width: 160
        },
        {
          title: '状态',
          dataIndex: 'auditStatusStr',
          width: this.STATUS_WIDTH,
          scopedSlots: { customRender: 'auditStatusStr' }
        },
        {
          title: '操作',
          dataIndex: 'operation',
          scopedSlots: { customRender: 'operation' },
          width: 220
        }
      ],
      loadData: q => {
        let p = Object.assign(q, this.queryParam)
        findListCount({}, p).then(res => {
          if (res.code === this.SUCCESS_CODE) this.statistics = res.data
        })
        return findListByMain({}, p)
      },
      temp: () => {
        return (
          <span>
                  待提交审核：{this.statistics.draft || 0}，
                  审核中：{this.statistics.submitted || 0}，
                  审核通过：{this.statistics.past || 0}，
                  审核不通过：{this.statistics.rejected || 0}
              </span>
        )
      }
    }
  },
  methods: {
    search(val = {}) {
      this.queryParam = val
      this.$refs.table.refresh()
    },
    handleDel(id) {
      let params = id ? [id] : this.selectId
      this.$delList2(deleteByMain, () => {
        this.search()
      }, { ids: params })
    },
    handleEdit(record, state) {
      this.$router.push({
        path: '/material/procurement/tenderAdd',
        query: {
          id: record && record.id || '',
          state: state
        }
      })
    }
  }
}
</script>
